/*
 * randomtestcardadventurer.c
 *
 *  Created on: Jul 23, 2014
 *      Author: Wing Yee Leung
 *
 * Note: This is a random unit test for the adventurer card
 * 		 The card is of type Action.
 *		 Effect is reveal cards from deck until 2 Treasure cards are revealed.
 *		 Put treasure cards in hand and discard the other revealed cards.
 *		 Cost is 3 Coins.
 */

 		
		
#include "dominion.h"
#include "dominion_helpers.h"
#include "rngs.h"
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include <time.h>

#define TESTCARD "adventurer"
#define NUMTESTS 15000

void zzzadventurercardplay(int drawntreasure, int currentPlayer, int cardDrawn, int temphand[MAX_HAND], int z, struct gameState* state);


int main() {

	int i, j, l, m, n, deckCt, discardCt, handCt, handPos, numPlayers, treasureCt;
	int thisPlayer, pass = 1, fail = 0, top1, top2;
 	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		sea_hag, tribute, smithy}; 	
	srand(time(NULL));

	printf("----------------- Testing Card: %s ----------------\n", TESTCARD);

	for(j = 0; j < NUMTESTS; j++) {

		printf("Test %d:\n", j);
	
		SelectStream(j % 255);
		
		struct gameState G;
		memset(&G, 0, sizeof(struct gameState));

		int temphand[MAX_HAND];
		
		//randomize card counts

		handCt = (int)floor(Random() * MAX_HAND);
		deckCt = (int)floor(Random() * (MAX_DECK - handCt));
		discardCt = (int)floor(Random() * (MAX_DECK - deckCt));
				
		//randomize and set number of players
		numPlayers = 2 + (int)floor(Random() * (MAX_PLAYERS - 2)); 
		//initialize game
		initializeGame(numPlayers, k, rand(), &G);
		
		//variables for zzzadventurercardplay
		int drawntreasure = 0, cardDrawn = 0, z = 0;
		
		
		G.numPlayers = numPlayers;
	
		//set current player
		thisPlayer = (int)floor(Random() * numPlayers);

		//set card counts
		G.handCount[thisPlayer] = handCt;
		G.deckCount[thisPlayer] = deckCt;
		G.discardCount[thisPlayer] = discardCt;
		
		
		//randomize and fill player's hand 
		for(i = 0; i < handCt; i++) {
			G.hand[thisPlayer][i] = (int)floor(Random() * 26);
		}
		
		//randomize and fill player's deck 
		for(m = 0; m < deckCt; m++) {
			G.deck[thisPlayer][m] = (int)floor(Random() * 26);
		}	
		
		//randomize and fill discard deck 
		for(n = 0; n < discardCt; n++) {
			G.discard[thisPlayer][n] = (int)floor(Random() * 26);
		}	
		
		//call function
		zzzadventurercardplay(drawntreasure, thisPlayer, cardDrawn, temphand, z, &G);
		
		top1 = G.hand[thisPlayer][G.handCount[thisPlayer] - 1];
		top2 = G.hand[thisPlayer][G.handCount[thisPlayer] - 2];
	
		printf("\tHand count = %d, expected = %d\n", G.handCount[thisPlayer], handCt + 2);
		printf("\tTop card of hand = %d, expected = %d, %d, or %d\n", top1, copper, silver, gold);
		printf("\tSecond card of hand = %d, expected = %d, %d, or %d\n", top2, copper, silver, gold);		
		printf("\tDeck Count: %d\n", G.deckCount[thisPlayer]);
		
		//check that result is correct		
		if(G.handCount[thisPlayer] == handCt + 2) {
			printf("\t\tPASS: hand count accurate.\n");
		}
		else {
			printf("\t\tFAIL: hand count inaccurate.\n");
			fail++;
			pass = 0;
		}
		if(top1 == copper || top1 == silver || top1 == gold) {
			printf("\t\tPASS: top of deck accurate.\n");
		}
		else {
			printf("\t\tFAIL: top of deck inaccurate.\n");
		}
		if(top2 == copper || top2 == silver || top2 == gold) {
			printf("\t\tPASS: 2nd of deck accurate.\n");
		}
		else {
			printf("\t\tFAIL: 2nd of deck inaccurate.\n");
		}	
		
	}
	
	
	if(pass == 1)
		printf("\n >>>>> SUCCESS: Testing complete for %s <<<<<\n\n", TESTCARD);
	else {
		printf("\n >>>>> FAIL: Not all tests passed for %s <<<<<\n\n", TESTCARD);
		printf("\n >>>>> Number of failed tests: %d/%d  <<<<<\n\n ", fail, NUMTESTS);
	}
	return 0;
}





